Previous sections described various customizations and extensions of SharePoint Learning Kit that are possible without programming. However, if you're comfortable using a .NET-compatible programming language such as C# or Visual Basic, you can use the SLK API (application programming interface) within your own programs to access a deeper level of SLK functionality. This section explains how.
Note Although you can access the SLK API using any programming language compatible with the .NET common language runtime (CLR), the code samples in this documentation are all written in C#.
The SLK API is implemented in a .NET 2.0 managed-code assembly named SharePointLearningKit.dll. This DLL makes use of Microsoft Learning Components (MLC). When SLK is installed on a SharePoint front-end server, both SLK and MLC DLLs are copied to the global assembly cache.
To access the SLK API, add a reference to the SharePointLearningKit.dll to your application. To create the reference, you'll need a copy of the DLL file—you can get the DLL, as well as MLC DLLs, from the SLK/MLC SDK. Depending on what your application needs to accomplish, you may need to add references to MLC DLLs as well—see Microsoft Learning Components for more information.
A SLK store is a collection of SharePoint Learning Kit information related to a single SharePoint site collection (SPSite). One site collection can map to one SLK store. A SLK store contains the following information:
Sometimes this documentation uses the term "SLK database" to refer to a SLK store, but in fact a single SLK database can include multiple SLK stores. (The reverse is not true: at most one SLK database can be associated with a given SharePoint site collection.) SLK uses the site collection GUID (the globally unique identifier stored in the property SPSite.ID) of each site collection to identify it within a SLK database.
In addition to information stored in the SLK database, each SLK store maintains a file system cache of unzipped e-learning package files, to improve performance. This cache can be maintained per-server farm or per-front end server, and cached content can be set to expire after a given interval. See SLK Settings for more information.
A SLK store is represented in a program by the SlkStore class. An application creates an instance of SlkStore using SlkStore.GetStore, as follows:
Web-based applications that execute within SharePoint (i.e. installed within the SharePoint's Template\Layouts directory) can call SharePoint's SPControl.GetContextWeb method to retrieve the current SPWeb, and then pass that SPWeb to SlkStore.GetStore as follows:
| C# |
using (SPWeb spWeb = SPControl.GetContextWeb(HttpContext.Current))
{
SlkStore slkStore = SlkStore.GetStore(spWeb);
...your code here...
}
|
For examples in context, see the Report1.aspx or Report2.aspx sample code. Also, SampleWebService.asmx demonstrates how to create a SlkStore instance from a Web service.
Alternatively, any application running on the SharePoint front-end server, including a desktop application, console application, or Windows service, can create an instance of SlkStore as follows:
| C# |
// "log in" to SharePoint as the user running this program, and set spUser to the SharePoint
// user whose login name is loginName (for example, "somedomain\someuser")
SPUser spUser;
using (SPSite anonymousSite = new SPSite(webUrl))
{
using (SPWeb rootWeb = anonymousSite.RootWeb)
{
spUser = rootWeb.AllUsers[loginName];
}
}
// "log in" to SharePoint again, this time as the user spUser
using (SPSite spSite = new SPSite(webUrl, spUser.UserToken))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
SlkStore slkStore = SlkStore.GetStore(spWeb);
...your code here...
}
}
|
Above, webUrl is the URL of the SharePoint Web site (SPWeb) that will provide context information to SLK; specifically, the SharePoint site collection (SPSite) of that Web site is mapped to the SLK database. loginName can be the login name of any SharePoint user that has access to that Web site. Note that the user running the application must have permission to directly access the SharePoint database since the code will be executing on behalf of a given SharePoint user.
For examples in context, see CreateAssignments.cs and AddToUserWebLists.cs (sample console applications).
In addition to providing access to information in a SLK store, a SlkStore object holds the identity of the Web browser user, often referred to as the current user in this documentation set. (For non-Web-based applications, such as console or desktop applications, the current user is the user running the application.) This information helps determine what operations are authorized. For example, if the application uses LearningStore to access LearnerAssignmentListForLearners, only those learner assignments for which the current user is a learner are returned.
Note SharePoint Learning Kit and Microsoft Learning Components assist with authorization tasks, but are not responsible for authenticating the current user. That is the responsibility of the application. In the case of SLK, SharePoint is responsible for authenticating the user, i.e. securely determining the user's identity. (Therefore, SLK supports SharePoint's authentication providers, including Windows integrated authentication and forms-based authentication.)
Programming tasks:
A learner assignment can be in one of four basic states, represented by values of the LearnerAssignmentState enumeration:
For assignments of e-learning packages, LearnerAssignmentState is determined by a combination of two pieces of information:
These pieces of information combine to form LearnerAssignmentState as follows. Also shown is the learner assignment "status" string displayed in SLK user interface. The first two columns are input conditions; the last two columns are the result of those conditions.
| AttemptStatus | IsFinal | LearnerAssignmentState | User Interface |
| None (attempt not begun) | false | LearnerAssignmentState.NotStarted | "Not Started" |
| AttemptStatus.Active | false | LearnerAssignmentState.Active | "In Progress" |
| AttemptStatus.Suspended | false | ||
| AttemptStatus.Completed | false | LearnerAssignmentState.Completed | "Submitted" |
| AttemptStatus.Abandoned | false | ||
| AttemptStatus.Completed | true | LearnerAssignmentState.Final | "Final" |
| AttemptStatus.Abandoned | true |
SLK queries and query sets, defined within the SLK Settings file associated with a SLK store, define what queries and query results users see in SLK's Assignment List Web Part. Applications can access SLK queries and query sets programmatically, to perform the same queries and display the results in whatever manner makes most sense for them.
Programming tasks:
The SlkSPSiteMapping class represents the mapping between a SharePoint SPSite and a SharePoint Learning Kit store. This mapping is stored in the SharePoint configuration database, and can be created, updated, and retrieved using any of the following approaches:
A SlkSPSiteMapping object contains the following information, accessible through properties on the object:
The static SlkAdministration class contains methods that mirror the functionality of the SharePoint Learning Kit Configuration page within SharePoint Central Administration.
Programming tasks: